package com.example.mvpdemo.simple6.base;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public abstract class BaseActivity6<V extends BaseView6, P extends BasePresnter6<V>> extends AppCompatActivity {
    private P presnter;
    private V view;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(this.presnter == null)
        {
            this.presnter = creatPresnter();
        }
        if(this.view == null)
        {
            this.view = creatView();
        }

        if(this.presnter != null && this.view != null)
        {
            this.presnter.attachView(view);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(this.presnter != null && this.view != null)
        {
            this.presnter.detachView();
        }
    }

    public P getPresnter() {
        return presnter;
    }

    public abstract P creatPresnter();
    public abstract V creatView();
}
